#include "ClientConnectionLibraryImpl.h"
#include "FeedConnectorImpl.h"

namespace AlgoTrading
{
	namespace ConnectionLibrary
	{

		ClientConnectionLibraryImpl::ClientConnectionLibraryImpl()
			: io_service(new boost::asio::io_service())
		{
		}

		void ClientConnectionLibraryImpl::Start()
		{
			thread = std::auto_ptr<boost::thread>(new boost::thread(boost::bind(&ClientConnectionLibraryImpl::ProcessingCycle, this)));
		}

		void ClientConnectionLibraryImpl::ProcessingCycle()
		{
			boost::asio::io_service::work work(*io_service);
			io_service->run();
		}

		void ClientConnectionLibraryImpl::Stop()
		{
			io_service->stop();
			thread->join();
		}

		std::auto_ptr<FeedConnector> ClientConnectionLibraryImpl::CreateFeedConnector(std::tr1::weak_ptr<NotificationHandler> notificationHandler)
		{
			return std::auto_ptr<FeedConnector>(new FeedConnectorImpl(*io_service, notificationHandler));
		}

	}
}